package org.mparts.client.place;

import org.mparts.client.activity.MainActivity;
import org.mparts.client.mvp.ActivityPlace;

import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class MainPlace extends ActivityPlace<MainActivity> {

	public static final String VIEW_HISTORY_TOKEN = "!main";

	@Inject
	public MainPlace(MainActivity activity) {
		super(activity);
	}

	@Prefix(value = VIEW_HISTORY_TOKEN)
	public static class Tokenizer implements PlaceTokenizer<MainPlace> {

		private final Provider<MainPlace> placeProvider;

		@Inject
		public Tokenizer(Provider<MainPlace> placeProvider) {
			this.placeProvider = placeProvider;
		}

		@Override
		public MainPlace getPlace(String token) {
			MainPlace place = placeProvider.get();
			place.setPlaceName(token);
			return place;
		}

		@Override
		public String getToken(MainPlace place) {
			return place.getPlaceName();
		}
	}

	@Override
	public String getHistoryToken() {
		return VIEW_HISTORY_TOKEN;
	}
}
